home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
dt01
/
dt01.frm
< prev
next >
Wrap
Text File
|
1995-09-06
|
16KB
|
461 lines
VERSION 2.00
Begin Form frmCalendar
AutoRedraw = -1 'True
BackColor = &H00C0C0C0&
BorderStyle = 0 'None
ClientHeight = 1020
ClientLeft = 1335
ClientTop = 1710
ClientWidth = 1950
ForeColor = &H00000000&
Height = 1425
Left = 1275
ScaleHeight = 1020
ScaleWidth = 1950
Top = 1365
Width = 2070
Begin PictureBox gpMonthSpin
BackColor = &H00C0C0C0&
Height = 252
Index = 2
Left = 1320
ScaleHeight = 225
ScaleWidth = 270
TabIndex = 2
Top = 120
Width = 300
End
Begin PictureBox gpMonthSpin
BackColor = &H00C0C0C0&
Height = 252
Index = 1
Left = 360
ScaleHeight = 225
ScaleWidth = 270
TabIndex = 3
Top = 120
Width = 300
End
Begin PictureBox pic
AutoRedraw = -1 'True
BackColor = &H00C0C0C0&
BorderStyle = 0 'None
FontTransparent = 0 'False
ForeColor = &H00000000&
Height = 372
Left = 480
ScaleHeight = 375
ScaleWidth = 375
TabIndex = 0
Top = 480
Width = 372
End
Begin Timer TmrMonthSpin
Enabled = 0 'False
Interval = 200
Left = 1320
Top = 480
End
Begin Label lblMonthText
Alignment = 2 'Center
BackColor = &H00C0C0C0&
Caption = "lMonth"
Height = 192
Left = 720
TabIndex = 1
Top = 120
Width = 564
End
End
Option Explicit
' Create form level globals?
Dim nCurrentYear As Integer
Dim nCurrentMonth As Integer
Dim nCurrentDay As Integer
Dim nStartDay As Integer
Dim nTotalDays As Integer
Dim nBlockNdx As Integer
Dim nCopyBlockNdx As Integer
Dim nBlockHeight As Integer
Dim nWidth As Integer
Dim nHeight As Integer
Sub Form_Activate ()
' Initialize form level date variables.
' -------------------------------------
If IsDate(gDate) Then
nCurrentYear = Year(gDate)
nCurrentMonth = Month(gDate)
nCurrentDay = Day(gDate)
Else
nCurrentYear = Year(Now)
nCurrentMonth = Month(Now)
nCurrentDay = Day(Now)
End If
' print days of the month.
' ------------------------
PrintMonth
End Sub
'================================================
' = Get all the static non-moving bits out here =
'================================================
Sub Form_Load ()
Dim i As Integer
Dim nOldWidth As Integer
' Set width/height of one char.
' -----------------------------
nWidth = TextWidth("M") ' Change this for bigger/smaller calendars.
nHeight = nWidth * 1.9
' resize the form.
' ----------------
Me.Height = (nHeight * 6) + (nHeight * .75)
Me.Width = ((nWidth * 2) * 7) + (nWidth * 1.25)
' position left/right arrows.
' ---------------------------
gpMonthSpin(1).Top = nHeight / 4
gpMonthSpin(2).Top = nHeight / 4
gpMonthSpin(1).Left = nWidth / 2
gpMonthSpin(2).Left = Width - gpMonthSpin(1).Width - (nWidth / 2)
' position month label between l/r arrows.
' ----------------------------------------
lblMonthText.Top = nHeight / 4
lblMonthText.Left = gpMonthSpin(1).Left + gpMonthSpin(1).Width
lblMonthText.Width = gpMonthSpin(2).Left - lblMonthText.Left
' size background panel.
' ----------------------
pic.Top = (nHeight * 2.25)
pic.Left = (nWidth / 2)
pic.Width = ((nWidth * 2) * 7) + 20
pic.Height = (nHeight * 4) + 50
' Output Day text.
' ----------------
For i = 1 To 7
CurrentY = nHeight * 1.25
CurrentX = (i * (nWidth * 2)) - (nWidth * 1.5)
Print Mid$("SuMoTuWeThFrSa", i * 2 - 1, 2)
Next
' draw separator line + shadow.
' -----------------------------
Line (0, nHeight * 2)-(Width, nHeight * 2), QBColor(0)
Line (0, nHeight * 2 + (nHeight / 29))-(Width, nHeight * 2 + (nHeight / 29)), QBColor(15)
' Attempt at a 3D border.
' -----------------------
nOldWidth = Me.DrawWidth
Me.DrawWidth = 10
Me.Line (-30, -30)-Step(Me.Width + 50, 0), QBColor(15)
Me.Line -Step(0, Me.Height + 40), QBColor(8)
Me.Line -Step(-(Me.Width + 50), 0), QBColor(8)
Me.Line -Step(0, -(Me.Height + 40)), QBColor(15)
Me.DrawWidth = nOldWidth
End Sub
' =============================================================
' Name.........: GetNumDaysInMonth(nYear, nMonth)
' Description..: Computes the number of days in any given month
' Parameters...: <nYear> - needed to check for leap years
' <nMonth> - the month number (1-12)
' Returns......: An integer representing the days in the month
' =============================================================
Function GetNumDaysInMonth (nYear As Integer, nMonth As Integer) As Integer
Dim cMonth As String, nDays As Integer
cMonth = "312831303130313130313031"
' Set defaults.
' -------------
If nYear < 100 Or nYear > 9999 Then nYear = Year(Now)
If nMonth < 1 Or nMonth > 12 Then nMonth = Month(Now)
' Set the number of days in the requested month.
' ----------------------------------------------
nDays = Val(Mid$(cMonth, nMonth * 2 - 2 + 1, 2))
' Compensate if requested year is a leap year, and month is February.
' -------------------------------------------------------------------
If IsLeapYear(nYear) And nMonth = 2 Then nDays = nDays + 1
GetNumDaysInMonth = nDays
End Function
Sub gpMonthSpin_MouseDown (Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
gpMonthSpin(Index).PictureDnChange = 2
TmrMonthSpin.Interval = 500
TmrMonthSpin.Enabled = True
TmrMonthSpin.Tag = Choose(Index, -1, 1)
nCurrentMonth = nCurrentMonth + TmrMonthSpin.Tag
PrintMonthText
End Sub
Sub gpMonthSpin_MouseUp (Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
gpMonthSpin(Index).PictureDnChange = 0
' turn off timer
TmrMonthSpin.Enabled = False
PrintMonth
End Sub
' =============================================================
' Name.........: IsLeapYear( nYear )
' Description..: Determines if a year is a leap year, or not.
' Parameters...: <nYear> -
' Returns......: An integer (boolean). True = it is a leap year
' =============================================================
Function IsLeapYear (nYear)
' If the year is evenly divisible by 4 and not divisible
' by 100, or if the year is evenly divisible by 400, then
' it's a leap year.
IsLeapYear = (nYear Mod 4 = 0 And nYear Mod 100 <> 0) Or (nYear Mod 400 = 0)
End Function
Sub pic_Click ()
' Return to 'sub-level' code.
' ---------------------------
If nCurrentDay > 0 Then
gDate = DateSerial(nCurrentYear, nCurrentMonth, nCurrentDay)
Me.Hide
End If
End Sub
Sub pic_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
' Just pass it along to "MouseMove".
' ----------------------------------
pic_MouseMove Button, Shift, x, y
End Sub
Sub pic_MouseMove (Button As Integer, Shift As Integer, x As Single, y As Single)
Dim i As Integer
Dim xt As Integer, x1 As Integer, x2 As Integer
Dim yt As Integer, y1 As Integer, y2 As Integer
' OK. The mouse is moving over the picture. Do we care?
' Only if the left mouse button is pressed.
' We then